package com.soft.app.ruanba.down;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

import org.xml.sax.helpers.DefaultHandler;

public class ImgDownloadHandler extends DefaultHandler {
	private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ImgDownloadHandler.class);
	private java.util.Stack tags;
	private static int i = 1;
	private ImgVo imgVo;
	private List<ImgVo> images;

	public ImgDownloadHandler()
	{
		tags = new Stack();
		images = new ArrayList<ImgVo>();
		imgVo = null;
	}

	public List<ImgVo> getImages() {
		return images;
	}

	public void setImages(List<ImgVo> images) {
		this.images = images;
	}

	public void startDocument()
		throws org.xml.sax.SAXException
	{
		log.info("开始解析");
	}

	public void characters(char ch[], int start, int length)
		throws org.xml.sax.SAXException
	{
		java.lang.String tag = (java.lang.String)tags.peek();
		java.lang.String value = new String(ch, start, length);
		if (tag.equals("image"))
			imgVo.setName(value);
	}

	public ImgVo getImgVo() {
		return imgVo;
	}

	public void setImgVo(ImgVo imgVo) {
		this.imgVo = imgVo;
	}

	public void endDocument()
		throws org.xml.sax.SAXException
	{
		log.info("成功结束任务!");
	}

	public void endElement(java.lang.String uri, java.lang.String localName, java.lang.String name)
		throws org.xml.sax.SAXException
	{
		java.lang.String popName = (java.lang.String)tags.pop();
		if (name.equals("soft"))
			images.add(imgVo);
	}

	public void startElement(java.lang.String uri, java.lang.String localName, java.lang.String name, org.xml.sax.Attributes attributes)
		throws org.xml.sax.SAXException
	{
		tags.push(name);
		if (name.equals("soft"))
		{
			imgVo = new ImgVo();
		}
	}
}
